home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 June: Reference Library / Dev.CD Jun 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 28 / develop issue 28 code / sketch / source / appleevent / aerrequiredsuite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  4.2 KB  |  169 lines

  1. /****************************************************************************
  2.  * 
  3.  * AERRequiredSuite.c
  4.  * 
  5.  * Apple Event Registry (AER) Required Suite support
  6.  * 
  7.  ****************************************************************************/
  8.  
  9. #include "Sketch.h"
  10. #include "AERRequiredSuite.h"
  11. #include "AppleEvent.h"
  12. #include "Documents.h"
  13.  
  14. // Required Suite Event Handlers
  15.  
  16. static pascal OSErr     HandleOAPP    (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
  17. static pascal OSErr     HandleQUIT    (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
  18. static pascal OSErr     HandleODOC    (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
  19. static pascal OSErr     HandlePDOC    (AppleEvent *appleEvent, AppleEvent *reply, long refCon);
  20.  
  21. /*****************************************************************************
  22.  * 
  23.  * InstallRequiredSuiteHandlers
  24.  * 
  25.  * Called by InstallAEHandlers() at program initialization time
  26.  * 
  27.  *****************************************************************************/
  28.  
  29. Boolean 
  30. InstallRequiredSuiteHandlers()
  31. {
  32.     Boolean error;
  33.     
  34.     error = AEInstallEventHandler(    kCoreEventClass, 
  35.                                                 kAEOpenApplication,    
  36.                                                 NewAEEventHandlerProc(HandleOAPP), 
  37.                                                 0, 
  38.                                                 false);
  39.     
  40.     if (error == noErr) 
  41.         error = AEInstallEventHandler(kCoreEventClass, 
  42.                                                 kAEQuitApplication,    
  43.                                                 NewAEEventHandlerProc(HandleQUIT), 
  44.                                                 0, 
  45.                                                 false);
  46.     
  47.     if (error == noErr) 
  48.         error = AEInstallEventHandler(kCoreEventClass, 
  49.                                                 kAEOpenDocuments,    
  50.                                                 NewAEEventHandlerProc(HandleODOC), 
  51.                                                 0, 
  52.                                                 false);
  53.     
  54.     if (error == noErr) 
  55.         error = AEInstallEventHandler(kCoreEventClass, 
  56.                                                 kAEPrintDocuments,
  57.                                                 NewAEEventHandlerProc(HandlePDOC), 
  58.                                                 0, 
  59.                                                 false);
  60.             
  61.     return (error == noErr);
  62. }
  63.  
  64. /*****************************************************************************
  65.  * 
  66.  * HandleOAPP
  67.  * 
  68.  * AppleEvent processing to open the application
  69.  * 
  70.  *****************************************************************************/
  71.  
  72. static pascal OSErr HandleOAPP(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
  73. {
  74.     #pragma unused            (appleEvent, refCon)
  75.     
  76.     OSErr                        error        = noErr;
  77.     DocumentReference        document;
  78.                 
  79.     document = MakeNewDocument(NULL);
  80.     
  81.     if (document == nil)
  82.         error = memFullErr;
  83.         
  84.     PutReplyErrorNumber(reply, error);
  85.  
  86.     return error;
  87. }
  88.  
  89.  
  90. /*****************************************************************************
  91.  * 
  92.  * HandleQUIT
  93.  * 
  94.  * AppleEvent processing to quit the application
  95.  * 
  96.  *****************************************************************************/
  97.  
  98. static pascal OSErr HandleQUIT(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
  99. {    
  100.     #pragma unused            (reply, refCon)
  101.     OSErr                      error;
  102.     DescType                 saveOptions;
  103.     DescType                    actualType;
  104.     long                        actualSize;
  105.     
  106.     
  107.     error = AEGetParamPtr(appleEvent, 
  108.                                  keyAESaveOptions, 
  109.                                  typeEnumerated,
  110.                                  &actualType,
  111.                                  &saveOptions,
  112.                                  sizeof(saveOptions),
  113.                                  &actualSize);
  114.                                  
  115.     if (error == errAEDescNotFound)
  116.     {
  117.         saveOptions = kAEAsk;
  118.         error = noErr;
  119.     }
  120.     
  121.     if (error == noErr)
  122.         error = DoQuit(saveOptions);
  123.     
  124.     return noErr;
  125. }
  126.  
  127. /*****************************************************************************
  128.  * 
  129.  * HandleODOC
  130.  * 
  131.  * AppleEvent processing to open one or more documents
  132.  * 
  133.  *****************************************************************************/
  134.  
  135. static pascal OSErr HandleODOC(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
  136. {    
  137.     #pragma unused            (appleEvent, refCon)
  138.  
  139.     OSErr    error = errAEEventNotHandled;
  140.  
  141.     AEPutParamPtr(reply, keyErrorNumber, typeLongInteger, (Ptr)&error, sizeof(OSErr));    
  142.     
  143.     return error;
  144. }
  145.  
  146. /*****************************************************************************
  147.  * 
  148.  * HandlePDOC
  149.  * 
  150.  * AppleEvent processing to print one or more documents
  151.  * 
  152.  *****************************************************************************/
  153.  
  154. static pascal OSErr HandlePDOC(AppleEvent *appleEvent, AppleEvent *reply, long refCon)
  155. {    
  156.     #pragma unused            (appleEvent, refCon)
  157.  
  158.     OSErr    error = errAEEventNotHandled;
  159.  
  160.     AEPutParamPtr(reply, keyErrorNumber, typeLongInteger, (Ptr)&error, sizeof(OSErr));    
  161.     
  162.     return error;
  163. }
  164.  
  165. // ---------------------------------------------------------------------------------
  166.  
  167.  
  168.  
  169.